      1  import java.io.File;

      2  import java.sql.Connection;

      3  import java.sql.ResultSet;

      4  import java.sql.Statement;

      5

      6  /**

      7     Tests a database installation by creating and querying

      8     a sample table. Call this program as

      9     java -classpath driver_class_path;. TestDB propertiesFile

     10  */

     11  public class TestDB

     12  {

     13     public static void main(String[] args) throws Exception

     14     {

     15        if (args.length == 0)

     16        {

     17           System.out.println(

     18                 "Usage: java -classpath driver_class_path"

     19                 + File.pathSeparator

     20                 + ". TestDB propertiesFile");

     21           return;

     22        }

     23

     24        SimpleDataSource.init(args[0]);

     25

     26        Connection conn = SimpleDataSource.getConnection();

     27        try

     28        {

     29           Statement stat = conn.createStatement();

     30

     31           stat.execute("CREATE TABLE Test (Name VARCHAR(20))");

     32           stat.execute("INSERT INTO Test VALUES ('Romeo')");

     33

     34           ResultSet result = stat.executeQuery("SELECT * FROM Test");

     35           result.next();

     36           System.out.println(result.getString("Name"));

     37

     38           stat.execute("DROP TABLE Test");

     39        }

     40        finally

     41        {

     42           conn.close();

     43        }

     44     }

     45  }